package router

import (
	api "buding-ai/internal/web/api"
	middleware "buding-ai/internal/web/middleware"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"time"
)

// Router 路由接口
type Router interface {
	// SetupRouter 设置路由
	SetupRouter(engine *gin.Engine)
}

// SetupRouter 配置所有路由
func SetupRouter(engine *gin.RouterGroup) {
	// 配置CORS中间件
	engine.Use(cors.New(cors.Config{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Content-Length", "Content-Type", "Authorization"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
		MaxAge:           12 * time.Hour,
	}))
	// 知识库管理
	knowledgeGroup := engine.Group("/knowledge", middleware.JWTAuth())
	api.NewKnowledgeApi(knowledgeGroup)

	// 对话管理
	chatGroup := engine.Group("/chat", middleware.JWTAuth())
	chat := api.NewChat(chatGroup)
	engine.GET("/chat/question/sse", chat.QuestionSSEStream)

	// 用户管理（需要管理员权限）
	userGroup := engine.Group("/user", middleware.JWTAuth(), middleware.AdminAuth())
	api.NewUserApi(userGroup)

	mcpGroup := engine.Group("/mcp", middleware.JWTAuth(), middleware.AdminAuth())
	api.NewMcpApi(mcpGroup)

	// 认证管理（不需要JWT认证）
	authGroup := engine.Group("/auth")
	api.NewAuthApi(authGroup)

	// 模型角色管理
	agentRoleGroup := engine.Group("/agent/role", middleware.JWTAuth(), middleware.AdminAuth())
	api.NewAgentRoleApi(agentRoleGroup)

	// oss
	ossGroup := engine.Group("/oss")
	api.NewCosApi(ossGroup)

	agentModelProviderGroup := engine.Group("/agent/modelProvider", middleware.JWTAuth())
	api.NewAgentModelProvidersApi(agentModelProviderGroup)
}
